package com.itheima.springbootenable;

import com.itheima.config.EnableUser;
import com.itheima.config.MyImportBeanDefinitionRegistrar;
import com.itheima.config.MyImportSelector;
import com.itheima.config.UserConfig;
import com.itheima.pojo.Role;
import com.itheima.pojo.User;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Import;
import redis.clients.jedis.Jedis;

/**
 * springboot是否阔以加载其他工程的bean  --》不阔以
 *
 * @SpringBootApplication 内的@ComponentScan注解扫描范围：该包及其子包下
 * @Import 注解，加载配置类。这些类都会被spring创建，并存放在IOC容器中
 * 4中方式
 * 1.Bean直接使用 User.class
 * 2.加载配置类
 * 3.加载ImportSelector的实现类的
 * 4.加载ImportBeanDefinitionRegistrar的实现类
 */
@SpringBootApplication
//@ComponentScan("com.itheima.config")
//@Import(UserConfig.class)
//@EnableUser
//@Import(MyImportSelector.class)
@Import(MyImportBeanDefinitionRegistrar.class)
public class SpringbootEnableApplication {

    public static void main(String[] args) {
        ConfigurableApplicationContext context = SpringApplication.run(SpringbootEnableApplication.class, args);
        //通过上下文对象获取指定的bean
        Object user = context.getBean(User.class);
        System.out.println(user);

        //通过上下文对象获取指定的bean
        /*Object Role = context.getBean(com.itheima.pojo.Role.class);
        System.out.println(Role);*/

        //获取自定义的redis -starter bean
        Jedis bean = context.getBean(Jedis.class);
        System.out.println(bean);
    }

}
